package com.itcast.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter(urlPatterns = "/*")
public class DemoFilter implements Filter {

    @Override //初始化方法，Web服务器启动，创建Filter时调用，只调用一次
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("Init 初始化方法执行了");
    }

    @Override // 拦截到请求之后调用，调用多次
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("DemoFilter：拦截到了请求......放行之前的逻辑");

        //放行
        chain.doFilter(request, response);

        System.out.println("DemoFilter：拦截到了请求......放行之后的逻辑");

    }

    @Override //销毁方法，服务器关闭时调用，只调用一次
    public void destroy() {
        System.out.println("destroy 销毁方法执行了");
    }
}
